﻿$.extend($.fn.tabs.methods, {
    /**
     * 绑定双击事件
     * @param {Object} jq
     * @param {Object} caller 绑定的事件处理程序
     */
    bindDblclick: function (jq, caller) {
        return jq.each(function () {
            var that = this;
            $(this).children("div.tabs-header").find("ul.tabs").undelegate('li', 'dblclick.tabs').delegate('li', 'dblclick.tabs', function (e) {
                if (caller && typeof (caller) == 'function') {
                    var title = $(this).text();
                    var index = $(that).tabs('getTabIndex', $(that).tabs('getTab', title));
                    caller(index, title);
                }
            });
        });
    },
    /**
     * 解除绑定双击事件
     * @param {Object} jq
     */
    unbindDblclick: function (jq) {
        return jq.each(function () {
            $(this).children("div.tabs-header").find("ul.tabs").undelegate('li', 'dblclick.tabs');
        });
    }
});

(function ($) {
    $.gridloader = function (param, success, error) {
        var opts = $(this).data().datagrid.options;
        $.ajax({
            url: opts.url,
            type: opts.method,
            data: param,
            success: function (data) {
                success(data);
            },
            error: function (e) {
                alert(e.statusText);
            }
        });
    }

    $.combobox_all = function (data) {
        data.unshift({ ID: 0, Name: '所有' });
        return data;
    }

    $.combotree_all = function (data) {
        for (var i = 0; i < data.length; i++) {
            if (data[i].PID == 0) {
                return [{
                    id: 0,
                    text: '所有',
                    state: "closed",
                    children: data
                }];
            } else {
                return data;
            }
        }
    }

})(jQuery);


//防止标签注入，将标签进行转义
$.extend($.fn.treegrid.defaults, {
    loadFilter: function (data) {
        for (var i = 0; i < data.length; i++) {
            for (var att in data[i]) {
                if (typeof (data[i][att]) == "string") {
                    data[i][att] = data[i][att].replace(/</g, "&lt;").replace(/>/g, "&gt;");
                }
            }
        }
        return data;
    }
});

$.extend($.fn.datagrid.defaults, {
    loadFilter: function (data) {
        for (var i = 0; i < data.length; i++) {
            for (var att in data[i]) {
                if (typeof (data[i][att]) == "string") {
                    data[i][att] = data[i][att].replace(/</g, "&lt;").replace(/>/g, "&gt;");
                }
            }
        }
        return data;
    }
});